package com.example.broadcast;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.media.MediaPlayer;
import android.util.Log;
import android.widget.Button;
import android.widget.Toast;

public class SMSReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO: This method is called when the BroadcastReceiver is receiving
        // an Intent broadcast.
        //throw new UnsupportedOperationException("Not yet implemented");

      /*  Toast.makeText(context,intent.getAction()+
                "\n消息内容是："
                +intent.getStringExtra("msg"),Toast.LENGTH_LONG).show();
        Log.d("tagcontext","123456789");

        MediaPlayer.create(context,R.raw.wish).start();*/


        Intent serviceIntent = new Intent(context,MyAudioService.class);
        //在广播组件里，通过上下文对象启动音乐播放组件
        context.startService(serviceIntent);
        //新建调用Activity组件的意图
        Intent activityIntent = new Intent(context,MainActivity.class);
        activityIntent.putExtra("iscast",true);
        //新建栈用来存放被启动的Activity（当已经存在时，只做移动处理）
        activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        //在广播组件里，通过上下文对象启动Activity组件
        context.startActivity(activityIntent);


    }
}
